package com.onetech.adrewards.free.adapters;


import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.onetech.adrewards.free.R;
import com.onetech.adrewards.free.objects.PointHistoryDTO;


public class PointHistoryListAdapter extends BaseAdapter {
	private class ExchangeViewHolder {
		public TextView coin;
		public TextView createdAt;
		public TextView adName;
//		public TextView type;
//		public TextView totalCoinExchanged;
	}

	private Activity activity;
	private List<PointHistoryDTO> listApps;
	private static LayoutInflater inflater = null;

	public PointHistoryListAdapter(Activity _activity) {
		activity = _activity;
		listApps = new ArrayList<PointHistoryDTO>();
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void updateAppList(List<PointHistoryDTO> _listAppDTOs) {
		listApps.clear();
		listApps.addAll(_listAppDTOs);
		notifyDataSetChanged();
	}

	public void insertAppList(List<PointHistoryDTO> _listAppDTOs) {
		listApps.addAll(_listAppDTOs);
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return listApps.size();
	}

	@Override
	public Object getItem(int arg0) {
		if (listApps == null) {
			return null;
		}
		return listApps.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ExchangeViewHolder viewHolder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.point_history_item_row_listview,parent, false);
			viewHolder = new ExchangeViewHolder();
			viewHolder.coin = (TextView) convertView
					.findViewById(R.id.coin);	
			viewHolder.createdAt = (TextView) convertView
					.findViewById(R.id.createDate);
			viewHolder.adName = (TextView) convertView
					.findViewById(R.id.adName);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ExchangeViewHolder) convertView.getTag();
		}
		PointHistoryDTO temp = listApps.get(position);
		viewHolder.coin.setText("+"+temp.getCoin() + "pt");
		viewHolder.createdAt.setText(temp.getCreated_at());
		viewHolder.adName.setText(temp.getAd_name());
		return convertView;
	}

}

